<?php //pack11class

class PostManager {

    public $traceEnabled=true;
    public static $postVars=array();
    public static $valuesDone=false;

    public static function setValues() {

        array_push(Tracer::$traceFrom,__CLASS__);

        if(array_key_exists("user", $_POST) && array_key_exists("pass", $_POST)) {
            $loginResult=Login::getUser($_POST["user"], $_POST["pass"]);
            if($loginResult) {
                $userin=SettingsManager::setSetting("userin",1);
                $userin->value=true;
            }
        }
        
        $postvals=array();

        foreach($_POST as $key=>$value) {
            array_push($postvals,$key."=".$value);
            if($property=PropertiesManager::getProperty($key)){
                $property->value=$value;
            }

            if($setting=SettingsManager::getSetting($key)){
                SettingsManager::setSetting($setting->id,$value);
                //trace($setting->system." ".$setting->value);
            }

            $pv=new PostItem;
            $pv->setID("post_".$key);
            $pv->setName($key);
            $pv->setBody($value);
            array_push(self::$postVars,$pv);

        }

        //trace(implode("; ",$postvals));

        foreach(PropertiesManager::properties() as $property) {
            //trace($property);
        }

        self::$valuesDone=true;
        $saveSetting=SettingsManager::getSetting("save");
        if($saveSetting->value) ObjectsManager::saveObject();
    }

    public static function getPostVars() {
        if(!self::$valuesDone) self::setValues();
        return self::$postVars;
    }

}
?>
